#!/usr/bin/env python
# -*- coding: utf-8 -*-
#__author__ = 'Medici.Yan'
#
import socket
import struct
'''
返回arg示例
{'host': '172.18.19.90', 'rpcinfo': [{'versions': '2,3,4', 'protocol': 'tcp', 'programnum': 100000, 'programname': 'rpcbind', 'port': 111}, {'versions': '2,3,4', 'protocol': 'udp', 'programnum': 100000, 'programname': 'rpcbind', 'port': 111}, {'versions': '2,3,4', 'protocol': 'tcp', 'programnum': 100003, 'programname': 'nfs', 'port': 2049}, {'versions': '2,3,4', 'protocol': 'udp', 'programnum': 100003, 'programname': 'nfs', 'port': 2049}, {'versions': 2, 'protocol': 'tcp', 'programnum': 100005, 'programname': 'mountd', 'port': 45156}, {'versions': 3, 'protocol': 'tcp', 'programnum': 100005, 'programname': 'mountd', 'port': 49931}, {'versions': 1, 'protocol': 'tcp', 'programnum': 100005, 'programname': 'mountd', 'port': 53650}]}
'''
'''
[root@localhost ~]# rpcinfo -p 172.18.19.90
   program vers proto   port  service
    100000    4   tcp    111  portmapper
    100000    3   tcp    111  portmapper
    100000    2   tcp    111  portmapper
    100000    4   udp    111  portmapper
    100000    3   udp    111  portmapper
    100000    2   udp    111  portmapper
    100011    1   udp    875  rquotad
    100011    2   udp    875  rquotad
    100011    1   tcp    875  rquotad
    100011    2   tcp    875  rquotad
    100005    1   udp  53492  mountd
    100005    1   tcp  53650  mountd
    100005    2   udp  33925  mountd
    100005    2   tcp  45156  mountd
    100005    3   udp  49226  mountd
    100005    3   tcp  49931  mountd
    100003    2   tcp   2049  nfs
    100003    3   tcp   2049  nfs
    100003    4   tcp   2049  nfs
    100227    2   tcp   2049  nfs_acl
    100227    3   tcp   2049  nfs_acl
    100003    2   udp   2049  nfs
    100003    3   udp   2049  nfs
    100003    4   udp   2049  nfs
    100227    2   udp   2049  nfs_acl
    100227    3   udp   2049  nfs_acl
    100021    1   udp  37443  nlockmgr
    100021    3   udp  37443  nlockmgr
    100021    4   udp  37443  nlockmgr
    100021    1   tcp  39414  nlockmgr
    100021    3   tcp  39414  nlockmgr
    100021    4   tcp  39414  nlockmgr
'''

service_dict={'100000':'rpcbind','100001':'rstatd','100002':'rusersd','100003':'nfs','100004':'ypserv','100005':'mountd','100006':'remote_dbx','100007':'ypbind','100008':'walld','100009':'yppasswdd','100010':'etherstatd','100011':'rquotad','100012':'sprayd','100013':'3270_mapper','100014':'rje_mapper','100015':'selection_svc','100016':'database_svc','100017':'rexd','100018':'alis','100019':'sched','100020':'llockmgr','100021':'nlockmgr','100022':'x25.inr','100023':'statmon','100024':'status','100025':'select_lib','100026':'bootparam','100027':'mazewars','100028':'ypupdated','100029':'keyserv','100030':'securelogin','100031':'nfs_fwdlnit','100032':'nfs_fwdtrns','100033':'sunlink_mapper','100034':'net_monitor','100035':'database','100036':'passwd_auth','100037':'tfsd','100038':'nsed','100039':'nsemntd','100040':'pfs_mountd','100041':'pnp_prog','100042':'ipaddr_alloc_prog','100043':'showfhd','100044':'mvsmount','100045':'rem_fileop_user_prog','100046':'batch_ypupdateprog','100047':'nem_prog','100048':'raytrace_rd_prog','100049':'raytrace_ld_prog','100050':'rem_fileop_group_prog','100051':'rem_fileop_system_prog','100052':'rem_system_role_prog','100055':'ioadmd','100056':'filemerge_prog','100057':'namebind_prog','100058':'njeprog','100059':'showattrd','100060':'rmgrprog','100061':'uidallocprog','100062':'NETlicense','100063':'lbbinderprog','100064':'gidallocprog','100065':'sunisamd','100066':'debug_svc','100068':'cmsd','100069':'ypxfrd','100070':'timedprog','100071':'bugtraqd','100075':'schedroom','100076':'authnegotiate_prog','100077':'attribute_prog','100078':'kerbd','100080':'rpc.operd','100081':'event_svc','100082':'bugtraq_qd','100083':'ttdbserverd','100087':'admind','100090':'libdsd/dsd','100092':'remote_activation_svc','100093':'host_checking','100095':'searchit','100096':'mesgtool','100098':'networked','100099':'autofsd','100100':'msgboard','100101':'event','100102':'logger','100103':'netmgt_topology_prog','100104':'sync','100105':'diskinfo','100106':'iostat','100107':'hostperf','100108':'netmgt_lprstatd_prog','100109':'activity','100110':'db_mgr','100111':'lpstat','100112':'hostmem','100113':'sample','100114':'x25','100115':'ping','100116':'rpcnfs','100117':'hostif','100118':'etherif','100119':'ippath','100120':'iproutes','100121':'layers','100122':'snmp','100123':'traffic','100124':'DNInode','100130':'rpc.localhad','100131':'layers2','100132':'na.tr','100133':'nsm_addrand','100134':'ktkt_warnd','100135':'etherif2','100136':'hostmem2','100137':'iostat2','100138':'snmpv2','100139':'sender','100140':'na.cpustat','100141':'rgmd_receptionist','100142':'fed','100143':'rdc','100144':'nafo','100145':'scadmd','100146':'amiserv','100147':'amiaux','100148':'dm','100149':'rkstat','100150':'ocfserv','100151':'sccheckd','100152':'autoclientd','100153':'sunvts','100154':'ssmond','100155':'smserverd','100156':'test1','100157':'test2','100158':'test3','100159':'test4','100160':'test5','100161':'test6','100162':'test7','100163':'test8','100164':'test9','100165':'test10','100166':'nfsmapid','100167':'SUN_WBEM_C_CIMON_HANDLE','100168':'sacmmd','100169':'fmd_adm','100170':'fmd_api','100172':'idmapd','100175':'na.snmptrap','100213':'ShowMe','100216':'keyrsa','100218':'sunsolve','100219':'cstatd','100220':'xfn_server_prog','100221':'kcms_server','100222':'ha_dbms_serv','100226':'hafaultd','100227':'nfs_acl','100228':'dlmd','100229':'metad','100230':'metamhd','100231':'nfsauth','100232':'sadmind','100233':'ufsd','100234':'gssd','100235':'cachefsd','100236':'msmprog','100237':'ihnamed','100238':'ihnetd','100239':'ihsecured','100240':'ihclassmgrd','100241':'ihrepositoryd','100242':'rpc.metamedd','100243':'contentmanager','100244':'sm_symond','100245':'pld','100246':'ctid','100247':'ccd','100248':'rpc.pmfd','100249':'snmpXdmid','100250':'mfs_admin','100251':'ndshared_unlink','100252':'ndshared_touch','100253':'ndshared_slink','100254':'cbs','100255':'skiserv','100256':'nfsxa','100257':'ndshared_disable','100258':'ndshared_enable','100259':'sms_account_admin','100260':'sms_modem_admin','100261':'sms_r_login','100262':'sms_r_subaccount_mgt','100263':'sms_service_admin','100264':'session_admin','100265':'canci_ancs_program','100266':'canci_sms_program','100267':'msmp','100268':'halck','100269':'halogmsg','100270':'nfs_id_map','100271':'ncall','100272':'hmip','100273':'repl_mig','100274':'repl_mig_cb','100281':'rpc.metacld','100300':'nisd','100301':'nis_cache','100302':'nis_callback','100303':'nispasswd','100304':'fnsypd','100399':'nfscksum','100400':'netmgt_netu_prog','100401':'netmgt_rping_prog','100402':'na.shell','100403':'na.picslp','100404':'traps','100410':'jdsagent','100411':'na.haconfig','100412':'na.halhost','100413':'na.hadtsrvc','100414':'na.hamdstat','100415':'na.neoadmin','100416':'ex1048prog','100417':'rpc.rdmaconfig','100422':'mdcommd','100423':'kiprop','100424':'stfsloader','100532':'ucmmstate','100533':'scrcmd','101002':'nselinktool','101003':'nselinkapp','105001':'sharedapp','105002':'REGISTRY_PROG','105003':'print-server','105004':'rpc.pts','105005':'notification-server','105006':'transfer-agent-server','110001':'tsolrpcb','110002':'tsolpeerinfo','110003':'tsolboot','120001':'cmip','120002':'na.osidiscover','120003':'cmiptrap','120100':'swu_svr','120101':'repserver','120102':'swserver','120103':'dmd','120104':'ca','120126':'nf_snmd','120127':'nf_snmd','150001':'pcnfsd','150006':'pcnfslicense','150007':'rdaprog','150008':'wsprog','150009':'wsrlprog','160001':'nihon-cm','160002':'nihon-ce','170100':'domf_daemon0','170101':'domf_daemon1','170102':'domf_daemon2','170103':'domf_daemon3','170104':'domf_daemon4','170105':'domf_daemon5','180000':'cecprog','180001':'cecsysprog','180002':'cec2cecprog','180003':'cesprog','180004':'ces2cesprog','180005':'cet2cetprog','180006':'cet2cetdoneprog','180007':'cetcomprog','180008':'cetsysprog','180009':'cghapresenceprog','180010':'cgdmsyncprog','180011':'cgdmcnscliprog','180012':'cgdmcrcscliprog','180013':'cgdmcrcssvcproG','180014':'chmprog','180015':'chmsysprog','180016':'crcsapiprog','180017':'ckptmprog','180018':'crimcomponentprog','180019':'crimqueryprog','180020':'crimsecondaryprog','180021':'crimservicesprog','180022':'crimsyscomponentprog','180023':'crimsysservicesprog','180024':'csmagtapiprog','180025':'csmagtcallbackprog','180026':'csmreplicaprog','180027':'csmsrvprog','180028':'cssccltprog','180029':'csscsvrprog','180030':'csscopresultprog','200000':'PyramidLock','200001':'PyramidSys5','200002':'CADDS_Image','200003':'stellar_name_prog','200005':'pdbDA','200006':'pacl','200007':'lookupids','200008':'ax_statd_prog','200009':'ax_statd2_prog','200010':'edm','200011':'dtedirwd','200016':'easerpcd','200017':'rlxnfs','200018':'sascuiddprog','200019':'knfsd','200020':'SWG','200021':'ftsyncd','200022':'ftstatd','200023':'exportmap','200024':'nfs_metadata','200034':'Gqsrv','200035':'Ppt','200036':'Pmt','200037':'Msgt','200038':'Walerts','200039':'Mgt','200040':'Pft','200041':'Msgq','200042':'Smpsrv','200043':'Dexsrv','200044':'Statussrv','200046':'SessionServer','200047':'SessionDaemon','200048':'Pmsgq','200049':'Filesrv','200050':'Magfetch','200051':'Optfetch','200052':'Securitysrv','200100':'bundle','200200':'bundle_demux','200201':'ecodisc','200202':'ecolic','200203':'eamon','200204':'cs_printstatus_svr','200205':'ecoad','211637':'rpc.dbserv','217843':'rpc.taped','217854':'rpc.taped','300001':'ADTFileLock','300002':'columbine1','300003':'system33_prog','300004':'rpc.frameusersd','300005':'uimxprog','300006':'fmclient','300007':'fmeditor','300008':'account','300009':'fmserver','300010':'beeper','300011':'dptuprog','300012':'mx-bcp','300013':'instrument-file-access','300014':'file-system-statistics','300015':'unify-database-server','300016':'tmd_msg','300019':'amd','300020':'lock','300021':'Steering','300022':'office-automation-1','300023':'office-automation-2','300024':'office-automation-3','300025':'office-automation-4','300026':'office-automation-5','300027':'office-automation-6','300028':'office-automation-7','300029':'rpc.ldmd','300030':'UpdtAuditsS','300031':'csi_program','300033':'online-help','300034':'case-tool','300035':'delta','300036':'rgi','300037':'instrument-config-server','300040':'dtia-rpc-server','300041':'cms','300042':'viewer','300043':'aqm','300044':'exclaim','300045':'masterplan','300046':'fig_tool','300050':'remote-lock-manager','300052':'gdebug','300053':'ldebug','300054':'rscanner','300066':'nSERVER','300071':'BioStation','300073':'NetProb','300074':'Logging','300075':'Logging','300082':'sw_twin','300083':'remote_get_login','300084':'odcprog','300091':'Dbpass','300092':'superping','300093':'distributed-chembench','300094':'uacman/alfil-uacman','300095':'ait_rcagent_prog','300096':'ait_rcagent_appl_prog','300097':'smart','300098':'ecoprog','300099':'leonardo','300108':'wingz','300109':'teidan','300116':'cadc_fhlockprog','300117':'highscan','300121':'opennavigator','300122':'aarpcxfer','300126':'groggs','300127':'licsrv','300128':'issdemon','300130':'maximize','300131':'cgm_server','300133':'agent_rpc','300134':'docmaker','300135':'docmaker','300139':'iesx','300144':'smart-mbs','300145':'clms','300147':'docimage','300149':'dmc-interface','300151':'jss','300153':'arimage','300154':'xdb-workbench','300155':'frontdesk','300156':'dmc','300157':'expressight-6000','300158':'graph','300176':'rlpr','300177':'nx_hostdprog','300178':'netuser-x','300179':'rmntprog','300181':'mipe','300183':'collectorprog','300184':'uslookup_PROG','300185':'viewstation','300186':'iate','300190':'imsvtprog','300194':'pmdb','300195':'pmda','300198':'trend_idbd','300199':'rres','300200':'sd.masterd','300201':'sd.executiond','300202':'sd.listend','300203':'sd.reserve1','300204':'sd.reserve2','300205':'msbd','300206':'stagedprog','300207':'mountprog','300208':'watchdprog','300209':'pms','300211':'session_server_program','300212':'session_program','300213':'debug_serverprog','300214':'fm_flb','300215':'fm_fls','300216':'paceprog','300218':'mbus','300219':'aframes2ps','300220':'npartprog','300221':'cm1server','300222':'cm1bridge','300223':'sailfrogfaxprog','300224':'sailfrogphoneprog','300225':'sailfrogvmailprog','300226':'wserviceprog','300227':'hld','300228':'alive','300229':'radsp','300230':'radavx','300231':'radview','300232':'rsys_prog','300233':'rsys_prog','300234':'fm_rpc_prog','300235':'aries','300236':'uapman','300237':'ddman','300238':'top','300240':'trendlink','300241':'licenseprog','300242':'statuslicenseprog','300243':'oema_rmpf_svc','300244':'oema_smpf_svc','300245':'oema_rmsg_svc','300246':'grapes-sd','300247':'ds_master','300248':'ds_transfer','300249':'ds_logger','300250':'ds_query','300253':'nsd_prog','300254':'browser','300255':'epoch','300256':'floorplanner','300257':'reach','300258':'tactic','300259':'cachescientific1','300260':'cachescientific2','300261':'desksrc_prog','300262':'photo3d1','300263':'photo3d2','300265':'soundmgr','300266':'s6k','300267':'aims_referenced_','300268':'xess','300269':'ds_queue','300271':'orionscanplus','300272':'openlink-xx','300273':'kbmsprog','300275':'futuresource','300276':'the_xprt','300277':'cmg_srvprog','300280':'front','300284':'conmanprog','300285':'jincv2','300286':'isls','300287':'systemstatprog','300288':'fxpsprog','300289':'callpath','300290':'axess','300291':'armor_rpcd','300292':'armor_dictionary_rpcd','300293':'armor_miscd','300294':'filetransfer_prog','300295':'bl_swda','300296':'bl_hwda','300300':'filemon','300301':'acuserve','300302':'rbuild','300303':'assistprog','300304':'tog','300306':'sns7000','300307':'igprog','300308':'tgprog','300309':'plc','300310':'pxman','300311':'hde_server','300312':'tsslicenseprog','300313':'rpc.explorerd','300314':'chrd','300315':'tbisam','300316':'tbis','300317':'adsprog','300318':'sponsorprog','300319':'querycmprog','300322':'mobil1','300323':'sld','300324':'linkprog','300325':'codexdaemonprog','300326':'dr_daemon','300327':'ressys_commands','300328':'stamp','300329':'matlab','300330':'sched1d','300331':'upcprog','300332':'xferbkch','300333':'xfer','300334':'qbthd','300335':'qbabort','300336':'lsd','300337':'geomgrd','300338':'generic_fts','300339':'ft_ack','300340':'lymb','300341':'vantage','300342':'cltstd','300343':'clui','300344':'testerd','300345':'extsim','300346':'cmd_dispatch','300347':'callpath_receive_program','300348':'x3270prog','300349':'sbc_lag','300350':'sbc_frsa','300351':'sbc_frs','300352':'atommgr','300353':'geostrat','300354':'dbvialu6.2','300356':'fxncprog','300357':'infopolic','300359':'aagns','300360':'aagms','300362':'clariion_mgr','300363':'setcimrpc','300364':'virtual_protocol_adapter','300365':'unibart','300366':'uniarch','300367':'unifile','300368':'unisrex','300369':'uniscmd','300370':'rsc','300371':'set','300372':'desaf-ws/key','300373':'reeldb','300374':'nl','300375':'rmd','300376':'agcd','300377':'rsynd','300378':'rcnlib','300379':'rcnlib_attach','300380':'evergreen_mgmt_agent','300381':'fx104prog','300382':'rui','300383':'ovomd','300386':'system_server','300387':'pipecs','300388':'uv-net','300389':'auexe','300390':'audip','300391':'mqi','300392':'eva','300393':'eeei_reserved_1','300394':'eeei_reserved_2','300395':'eeei_reserved_3','300396':'eeei_reserved_4','300397':'eeei_reserved_5','300398':'eeei_reserved_6','300399':'eeei_reserved_7','300400':'eeei_reserved_8','300401':'cprlm','300402':'wg_idms_manager','300403':'timequota','300404':'spiff','300405':'ov_oem_svc','300406':'ov_oem_svc','300407':'ov_oem_svc','300408':'ov_oem_svc','300409':'ov_oem_svc','300410':'ov_oem_svc','300411':'ov_oem_svc','300412':'ov_oem_svc','300413':'ov_oem_svc','300415':'ov_msg_ctlg_svc','300416':'ov_advt_reg_svc','300417':'showkron','300418':'showkron','300419':'showkron','300420':'showkron','300421':'showkron','300422':'showkron','300423':'showkron','300425':'daatd','300426':'swiftnet','300427':'ovomdel','300428':'ovomreq','300429':'msg_dispatcher','300430':'pcshare','300431':'rcvs','300432':'fdfserver','300433':'bssd','300434':'drdd','300435':'mif_gutsprog','300436':'mif_guiprog','300437':'twolfd','300438':'twscd','300439':'nwsbumv','300440':'dgux_mgr','300441':'pfxd','300442':'tds','300443':'ovomadmind','300444':'ovomgate','300445':'omadmind','300446':'nps','300447':'npd','300448':'tsa','300449':'cdaimc','300453':'ckt_implementation','300454':'mda-tactical','300459':'atrrun','300460':'RoadRunner','300461':'nas','300462':'undelete','300463':'ovacadd','300464':'tbdesmai','300465':'arguslm','300466':'dmd','300467':'drd','300468':'fm_help','300469':'ftransrpc_prog','300470':'finrisk','300471':'dg_pc_idisched','300472':'dg_pc_idiserv','300473':'ap_daemon','300474':'ap_sspd','300475':'callpatheventrecorder','300476':'flc','300477':'dg_osm','300478':'dspnamed','300479':'iqddsrv','300480':'iqjobsrv','300481':'tacosxx','300482':'wheeldbmg','300483':'cnxmond','300484':'cnxagentd','300485':'3dsmapper','300486':'ids','300487':'imagine_rpc_svc','300488':'lfn','300489':'salesnet','300490':'defaxo','300491':'dbqtsd','300492':'kms','300493':'rpc.iced','300494':'calc2s','300495':'ptouidprog','300496':'docsls','300497':'new','300498':'collagebdg','300499':'ars_server','300500':'ars_client','300501':'vr_catalog','300502':'vr_tdb','300503':'ama','300504':'evama','300505':'conama','300506':'service_process','300507':'reuse_proxy','300508':'mars_ctrl','300509':'mars_db','300510':'mars_com','300511':'mars_admch','300512':'tbpipcip','300513':'top_acs_svc','300514':'inout_svc','300515':'csoft_wp','300516':'mcserv','300517':'eventprog','300518':'dg_pc_idimsg','300519':'dg_pc_idiaux','300520':'atsr_gc','300521':'alarm','300522':'fts_prog','300523':'dcs_prog','300524':'ihb_prog','300527':'cluinfod','300528':'rmfm','300529':'c2sdocd','300530':'interahelp','300531':'callpathasyncmsghandler','300532':'optix_arc','300533':'optix_ts','300534':'optix_wf','300535':'maxopenc','300536':'cev','300537':'sitewideprog','300538':'drs','300539':'drsdm','300540':'dasgate','300541':'dcdbd','300542':'dcpsd','300543':'supportlink_prog','300544':'broker','300545':'listner','300546':'multiaccess','300547':'spai_interface','300548':'spai_adaption','300549':'chimera_ci','300550':'chimera_pi','300551':'teamware_fl','300552':'teamware_sl','300553':'teamware_ui','300554':'lprm','300555':'mpsprog','300556':'mo_symdis','300557':'retsideprog','300558':'slp','300559':'slm-api','300560':'im_rpc','300561':'license_prog','300562':'stuple','300563':'upasswd_prog','300564':'gentranmentorsecurity','300565':'gentranmentorprovider','300566':'latituded','300567':'gentranmentorreq1','300568':'gentranmentorreq2','300569':'gentranmentorreq3','300570':'rj_server','300571':'gws-rdb','300572':'gws-mpmd','300573':'gws-spmd','300574':'vwcalcd','300575':'vworad','300576':'vwsybd','300577':'vwave','300578':'online_assistant','300579':'internet_assistant','300580':'spawnd','300581':'procmgrg','300582':'cfgdbd','300583':'logutild','300584':'ibis','300585':'ibisaux','300586':'aapi','300587':'rstrt','300588':'hbeat','300589':'pcspu','300590':'empress','300591':'sched_server','300592':'path_server','300593':'c2sdmd','300594':'c2scf','300595':'btsas','300596':'sdtas','300597':'appie','300598':'dmispd','300599':'pscd','300600':'sisd','300601':'cpwebserver','300602':'wwcommo','300603':'mx-mie','300604':'mx-mie-debug','300605':'idmn','300606':'ssrv','300607':'vpnserver','300608':'samserver','300609':'sams_server','300610':'chrysalis','300611':'ddm','300612':'ddm-is','300613':'mx-bcp-debug','300614':'upmrd','300615':'upmdsd','300616':'res','300617':'colortron','300618':'zrs','300619':'afpsrv','300620':'apxft','300621':'nrp','300622':'hpid','300623':'mailwatch','300624':'fos','300625':'cs_sysadmin_svr','300626':'cs_controller_svr','300627':'nokia_nms_eai','300628':'dbg','300629':'remex','300630':'cs_bind','300631':'idm','300632':'prpasswd','300633':'iw-pw','300634':'starrb','300635':'Impress_Server','300636':'colorstar','300637':'gwugui','300638':'gwsgui','300639':'dai_command_proxy','300640':'dai_alarm_server','300641':'dai_fui_proxy','300642':'spai_command_proxy','300643':'spai_alarm_server','300644':'iris','300645':'hcxttp','300646':'updatedb','300647':'urnd','300648':'iqwpsrv','300649':'dskutild','300650':'online','300651':'nlserv','300652':'acsm','300653':'dg_clar_sormsg','300654':'wwpollerrpc','300655':'wwmodelrpc','300656':'nsprofd','300657':'nsdistd','300658':'recollect','300659':'lssexecd','300660':'lssagend','300661':'cdinfo','300662':'sninsr_addon','300663':'mm-sap','300664':'ks','300665':'psched','300666':'tekdvfs','300667':'storxll','300668':'nisse','300669':'lbadvise','300670':'atcinstaller','300671':'atntstarter','300672':'NetML','300673':'tdmesmge','300674':'tdmesmgd','300675':'tdmesmgt','300676':'olm','300677':'mediamanagement','300678':'rdbprog','300679':'rpwdprog','300680':'sapi-trace','300681':'sapi-master-daemon','300682':'omdcuprog','300683':'wwprocmon','300684':'tndidprog','300685':'rkey_setsecretprog','300686':'asdu_server_prog','300687':'pwrcntrl','300688':'siunixd','300689':'wmapi','300690':'cross_reference_ole','300691':'rtc','300692':'disp','300693':'sql_compilation_agent','300694':'tnsysprog','300695':'ius-sapimd','300696':'apteam-dx','300697':'rmsrpc','300698':'seismic_system','300699':'remote','300700':'tt1_ts_event','300701':'fxrs','300702':'onlicense','300703':'vxkey','300704':'dinis','300705':'sched2d','300706':'sched3d','300707':'sched4d','300708':'sched5d','300709':'sched6d','300710':'sched7d','300711':'sched8d','300712':'sched9d','300713':'adtsqry','300714':'adserv','300715':'adrepserv','300717':'caad','300718':'caaui','300719':'cescda','300720':'vcapiadmin','300721':'vcapi20','300722':'tcfs','300723':'csed','300724':'nothand','300725':'hacb','300726':'nfauth','300727':'imlm','300728':'bestcomm','300729':'lprpasswd','300730':'rprpasswd','300731':'proplistd','300732':'mikomomc','300733':'arepa-cas','300736':'ando_ts','300737':'intermezzo','300738':'ftel-sdh-request','300739':'ftel-sdh-response','300745':'vrc_abb','300746':'vrc_comau','300747':'vrc_fanuc','300748':'vrc_kuka','300749':'vrc_reis','300750':'hp_sv6d','300751':'correntmgr01','300752':'correntike','300755':'intransa_location','300756':'intransa_management','300757':'intransa_federation','300758':'portprot','300759':'ipmiprot','300760':'aceapi','300761':'f6000pss','300762':'vsmapi_program','300763':'ubertuple','300764':'ctconcrpcif','300765':'mfuadmin','300766':'aiols','300767':'dsmrootd','300768':'htdl','300769':'caba','300770':'vrc_cosimir','300771':'cmhelmd','300772':'polynsm','300781':'dsmrecalld','300784':'twrgcontrol','300785':'twrled','300786':'twrcfgdb','344444':'sfs','351350':'wfmMgmtApp','351351':'wfmMgmtDataSrv','351352':'wfmMgmtFut1','351353':'wfmMgmtFut1','351354':'wfmAPM','351355':'wfmIAMgr','351356':'wfmECMgr','351357':'wfmLookOut','351358':'wfmAgentFut1','351359':'wfmAgentFut2','351360':'sched10d','351361':'sched11d','351362':'sched12d','351363':'sched13d','351364':'sched14d','351365':'sched15d','351366':'sched16d','351367':'sched17d','351368':'sched18d','351369':'sched19d','351370':'sched20d','351371':'sched21d','351372':'sched22d','351373':'sched23d','351374':'sched24d','351375':'sched25d','351376':'sched26d','351377':'sched27d','351378':'sched28d','351379':'sched29d','351380':'sched30d','351381':'sched31d','351382':'sched32d','351383':'sched33d','351384':'sched34d','351385':'sched35d','351386':'sched36d','351387':'sched37d','351388':'sched38d','351389':'sched39d','351390':'consoleserver','351391':'scheduleserver','351392':'RDELIVER','351393':'REVENTPROG','351394':'RSENDEVENTPROG','351395':'snapp','351396':'snapad','351397':'sdsoodb','351398':'sdsmain','351399':'sdssrv','351400':'sdsclnt','351401':'sdsreg','351402':'fsbatch','351403':'fsmonitor','351404':'fsdisp','351405':'fssession','351406':'fslog','351407':'csed','351407':'svdpappserv','351408':'gns','351412':'axi','351413':'rpcxfr','351414':'slm','351415':'smbpasswdd','351416':'tbdbserv','351417':'tbprojserv','351418':'genericserver','351419':'dynarc_ds','351420':'dnscmdr','351421':'ipcmdr','351422':'faild','351423':'failmon','351424':'faildebug','351427':'siemens_srs','351428':'bsproxy','351429':'ifsrpc','351430':'CesPvcSm','351431':'FrPvcSm','351432':'AtmPvcSm','351433':'radius','351434':'auditor','351435':'sft','351436':'voicemail','351437':'kis','351438':'SOFTSERV_NOTIFY','351439':'dynarpc','351440':'hc','351441':'iopas','351442':'iopcs','351443':'iopss','351444':'spcnfs','351445':'spcvss','351446':'matilda_sms','351447':'matilda_brs','351448':'matilda_dbs','351449':'matilda_sps','351450':'matilda_svs','351451':'matilda_sds','351452':'matilda_vvs','351453':'matilda_stats','351454':'xtrade','351455':'mapsvc','351456':'hp_graphicsd','351457':'berkeleydb','351458':'io_server','351459':'rpc.niod','351460':'rpc.kill','351461':'hmdisproxy','351462':'smdisproxy','351463':'avatard','351464':'namu','351465':'BMCSess','351466':'FENS_Sport','351467':'EM_CONFIG','351468':'EM_CONFIG_RESP','351469':'lodge_proof','351470':'ARCserveIT-Queue','351471':'ARCserveIT-Device','351472':'ARCserveIT-Discover','351473':'caasalert','351474':'ARCserveIT-Database','351475':'scand1','351476':'scand2','351477':'scand3','351478':'scand4','351479':'scand5','351480':'dscv','351481':'cb_svc','351483':'iprobe','351484':'omniconf','351485':'isan','351501':'mond','351502':'iqlremote','351503':'iqlalarm','352233':'asautostart','352234':'asmediad1','352235':'asmediad2','352236':'asmediad3','352237':'asmediad4','352238':'asmediad5','352239':'asmediad6','352240':'asmediad7','352241':'asmediad8','352242':'asmediad9','352243':'asmediad10','352244':'asmediad11','352245':'asmediad12','352246':'asmediad13','352247':'asmediad14','352248':'asmediad15','352249':'asmediad16','352250':'waruser','352251':'warlogd','352252':'warsvrmgr','352253':'warvfsysd','352254':'warftpd','352255':'warnfsd','352256':'bofproxyc0','352257':'bofproxys0','352258':'bofproxyc1','352259':'bofproxys1','352260':'bofproxyc2','352261':'bofproxys2','352262':'bofproxyc3','352263':'bofproxys3','352264':'bofproxyc4','352265':'bofproxys4','352266':'bofproxyc5','352267':'bofproxys5','352268':'bofproxyc6','352269':'bofproxys6','352270':'bofproxyc7','352271':'bofproxys7','352272':'bofproxyc8','352273':'bofproxys8','352274':'bofproxyc9','352275':'bofproxys9','352276':'bofproxyca','352277':'bofproxysa','352278':'bofproxycb','352279':'bofproxysb','352280':'bofproxycc','352281':'bofproxysc','352282':'bofproxycd','352283':'bofproxysd','352284':'bofproxyce','352285':'bofproxyse','352286':'bofproxycf','352287':'bofproxysf','352288':'bofproxypo0','352289':'bofproxypo1','352290':'bofproxypo2','352291':'bofproxypo3','352292':'bofproxypo4','380000':'opensna','380001':'probenet','380003':'license','380004':'na.3com-remote','380005':'na.ntp','380006':'probeutil','380007':'na.vlb','380008':'cds_mhs_agent','380009':'cds_x500_agent','380010':'cds_mailhub_agent','380011':'codex_6500_proxy','380012':'codex_6500_trapd','380013':'na.nm212','380014':'cds_mta_metrics_agent','380016':'na.caple','380017':'codexcapletrap','380029':'ncstat','380030':'ncnfsstat','380031':'ftams','380032':'na.isotp','380033':'na.rfc1006','390100':'prestoctl_svc','390101':'rap','390102':'rapserv','390103':'nsrd','390104':'nsrmmd','390105':'nsrindexd','390107':'nsrmmdbd','390109':'nsrstat','390110':'nsrjb','390113':'nsrexec','390115':'lgtolmd','390116':'cdsmonitor','390117':'cdslock','390118':'cdslicense','390119':'shm','390120':'rws','390121':'cdc','390400':'nsrnotd','390600':'arserverd','390601':'ntserverd','390602':'ntclientd','390603':'aresclsrv','390604':'arservtcd','390610':'flashservd','390619':'arflashbd','390620':'arfastsrv','390621':'arfastsrv','390622':'arfastsrv','390623':'arfastsrv','390624':'arfastsrv','390625':'arfastsrv','390626':'arfastsrv','390627':'arfastsrv','390628':'arfastsrv','390629':'arfastsrv','390630':'arfastsrv','390631':'arfastsrv','390632':'arfastsrv','390633':'arfastsrv','390634':'arfastsrv','390635':'arlistsrv','390636':'arlistsrv','390637':'arlistsrv','390638':'arlistsrv','390639':'arlistsrv','390640':'arlistsrv','390641':'arlistsrv','390642':'arlistsrv','390643':'arlistsrv','390644':'arlistsrv','390645':'arlistsrv','390646':'arlistsrv','390647':'arlistsrv','390648':'arlistsrv','390649':'arlistsrv','391000':'sgi_snoopd','391001':'sgi_toolkitbus','391002':'sgi_fam','391003':'sgi_notepad','391004':'sgi_mountd','391005':'sgi_smtd','391006':'sgi_pcsd','391007':'sgi_nfs','391008':'sgi_rfind','391009':'sgi_pod','391010':'sgi_iphone','391011':'sgi_videod','391012':'sgi_testcd','391013':'sgi.ha_hbeat','391014':'sgi.ha_nc','391015':'sgi.ha_appmon','391016':'sgi_xfsmd','391017':'sgi_mediad','391018':'sgi.ha_orcl','391019':'sgi.ha_ifmx','391020':'sgi.ha_sybs','391021':'sgi.ha_ifa','391022':'sgi_reserved','391023':'sgi_reserved','391024':'sgi_reserved','391025':'sgi_reserved','391026':'sgi_reserved','391027':'sgi_reserved','391028':'sgi_reserved','391029':'sgi_espd','391030':'sgi_reserved','391031':'sgi_reserved','391032':'sgi_reserved','391033':'sgi_reserved','391034':'sgi_reserved','391035':'sgi_reserved','391036':'sgi_reserved','391037':'sgi_reserved','391038':'sgi_reserved','391039':'sgi_reserved','391040':'sgi_reserved','391041':'sgi_reserved','391042':'sgi_reserved','391043':'sgi_reserved','391044':'sgi_reserved','391045':'sgi_reserved','391046':'sgi_reserved','391047':'sgi_reserved','391048':'sgi_reserved','391049':'sgi_reserved','391050':'sgi_reserved','391051':'sgi_reserved','391052':'sgi_reserved','391053':'sgi_reserved','391054':'sgi_reserved','391055':'sgi_reserved','391056':'sgi_reserved','391057':'sgi_reserved','391058':'sgi_reserved','391059':'sgi_reserved','391060':'sgi_reserved','391061':'sgi_reserved','391062':'sgi_reserved','391063':'sgi_reserved','391200':'afsd','391201':'dhc','391202':'cmsd','391203':'xxx2trif','391204':'trif2xxx','391205':'dx','391206':'licd','391434':'ingsqld','391756':'naas-spare','391757':'naas-admin','391758':'isps','391759':'isps-admin','391760':'mars','391761':'mars-admin','391762':'attcis_spare0','391763':'attcis_spare1','391764':'mail-server','391765':'mail-server-spare','391766':'attcis_spare2','391767':'attcis_spare3','391768':'attcis_spare4','391769':'attcis_spare5','391770':'attcis_spare6','391771':'attcis_spare7','391850':'qhrdata','391851':'qhrbackup','391852':'minutedata','391853':'prefecture','391854':'supc','391855':'suadmincrw','391856':'suadminotas','391857':'sumessage','391858':'sublock','391859':'sumotd','391880':'namesrvr','391881':'disksrvr','391882':'tapesrvr','391883':'migsrvr','391884':'pdmsrvr','391885':'pvrsrvr','391886':'repacksrvr','391952':'lookoutsrv','391953':'lookoutagnt','391954':'lookoutprxy','391955':'lookoutsnmp','391956':'lookoutrmon','391957':'lookoutfut1','391958':'lookoutfut2','391968':'sra_legato','391969':'sra_legato_imgsvr','391970':'sra_legato_0','391971':'sra_legato_1','391972':'sra_legato_2','391973':'sra_legato_3','391974':'sra_legato_4','391975':'sra_legato_5','391976':'sra_legato_6','391977':'sra_legato_7','391978':'sra_legato_8','391979':'sra_legato_9','395024':'odbc_sqlretriever','395165':'ife-es','395166':'ife-resmgr','395167':'ife-aes','395168':'ife-bite','395169':'ife-loader','395170':'ife-satcom','395171':'ife-seat','395172':'ife-dbmgr','395173':'ife-testmgr','395174':'atrium_server','395175':'asedirector','395176':'aseagent','395177':'asehsm','395178':'ase_mgr','395179':'aselogger','395250':'pnictl','395644':'caservd','395645':'calqserver','395646':'camediadsvr','395647':'caldbserver','395648':'caauthd','395649':'cadiscovd','395650':'caloggerd','400000':'mcm','400001':'mcm','400002':'mcm','400003':'mcm','400004':'mcm','400005':'mcm','400006':'mcm','400007':'mcm','400008':'mcm','400010':'NetAppPartnerSvc','400011':'Oropo','400012':'Oropo','400013':'Oropo','400014':'Oropo','400015':'Oropo','400016':'Oropo','400017':'Oropo','400018':'Oropo','400019':'Oropo','400020':'Oropo','400021':'Oropo','400022':'Oropo','400023':'Oropo','400024':'Oropo','400025':'Oropo','400026':'Oropo','400027':'Oropo','400028':'Oropo','400029':'Oropo','400030':'Oropo','400031':'Oropo','400032':'Oropo','400033':'Oropo','400034':'Oropo','400035':'Oropo','400036':'Oropo','400037':'Oropo','400038':'Oropo','400039':'Oropo','400040':'Oropo','400041':'Oropo','400042':'Oropo','400043':'Oropo','400044':'Oropo','400045':'Oropo','400046':'Oropo','400047':'Oropo','400048':'Oropo','400049':'Oropo','400050':'Oropo','400051':'Oropo','400052':'Oropo','400053':'Oropo','400054':'Oropo','400055':'Oropo','400056':'Oropo','400057':'Oropo','400058':'Oropo','400059':'Oropo','400060':'Oropo','400061':'Oropo','400062':'Oropo','400063':'Oropo','400064':'Oropo','400065':'Oropo','400066':'Oropo','400067':'Oropo','400068':'Oropo','400069':'Oropo','400070':'Oropo','400071':'Oropo','400072':'Oropo','400073':'Oropo','400074':'Oropo','400075':'Oropo','400076':'Oropo','400077':'Oropo','400078':'Oropo','400079':'Oropo','400080':'Oropo','400081':'Oropo','400082':'Oropo','400083':'Oropo','400084':'Oropo','400085':'Oropo','400086':'Oropo','400087':'Oropo','400088':'Oropo','400089':'Oropo','400090':'Oropo','400091':'Oropo','400092':'Oropo','400093':'Oropo','400094':'Oropo','400095':'Oropo','400096':'Oropo','400097':'Oropo','400098':'Oropo','400099':'Oropo','400100':'Oropo','400101':'Oropo','400102':'Oropo','400103':'Oropo','400104':'Oropo','400105':'Oropo','400106':'Oropo','400107':'Oropo','400108':'Oropo','400109':'Oropo','450000':'EnsignAgent','900101':'drac','1000002':'AdoIfServer','2000004':'notifServer','20000000':'retherif','20000001':'genagnt','20000114':'acedb','20000115':'aboutdb','20000116':'aatdb','20000777':'seagent','21000023':'dbsrvr','28000205':'egts','28000220':'ers','28000230':'sas','200100001':'netinfobind','200100002':'renderd','536870913':'SLSd_daemon','536870915':'uidd','536870916':'vtsk','536870917':'bondd','536870918':'staticd','536870919':'curved','536870920':'msglogd','536870921':'aliasd','536870922':'ticketd','536870923':'glossd','536870924':'futured','536870928':'priced','536870929':'ladderd','536870937':'optiond','536870944':'ndbportmgr','536870945':'ndbserver1','536870946':'ndbserver2','536870947':'ndbserver3','536870948':'ndbserver4','536870949':'ndbserver5','536870950':'ndbserver6','536870951':'ndbserver7','536870952':'ndbserver8','536870953':'ndbserver9','536870954':'ndbserver10','536870955':'ndbserver11','536870956':'ndbserver12','536870957':'ndbserver13','536870958':'ndbserver14','536870959':'ndbserver15','536870960':'ndbserver16','536870961':'ndbserver17','536870962':'ndbserver18','536870963':'ndbserver19','536870964':'ndbserver20','536870965':'ndbserver21','536870966':'ndbserver22','536870967':'ndbserver23','536870968':'ndbserver24','536870969':'ndbserver25','536870970':'ndbserver26','536870971':'ndbserver27','536870972':'ndbserver28','536870973':'ndbserver29','536870974':'ndbserver30','536870975':'ndbserver31','536870976':'ndbserver32','536870977':'ndbserver33','536870978':'ndbserver34','536870979':'ndbserver35','536870980':'ndbserver36','536870981':'ndbserver37','536870982':'ndbserver38','536870983':'ndbserver39','536870984':'ndbserver40','536870985':'ndbserver41','536870986':'ndbserver42','536870987':'ndbserver43','536870988':'ndbserver44','536870989':'ndbserver45','536870990':'ndbserver46','536870991':'ndbserver47','536870992':'ndbserver48','536870993':'ndbserver49','536870994':'ndbserver50','536870995':'ndbserver51','536870996':'ndbserver52','536870997':'ndbserver53','536870998':'ndbserver54','536870999':'ndbserver55','536871000':'ndbserver56','536871001':'ndbserver57','536871002':'ndbserver58','536871003':'ndbserver59','536871004':'ndbserver60','536871005':'ndbserver61','536871006':'ndbserver62','536871007':'ndbserver63','536871008':'ndbserver64','536871009':'ndbserver65','536871010':'ndbserver66','536871011':'ndbserver67','536871012':'ndbserver68','536871013':'ndbserver69','536871014':'ndbserver70','536871015':'ndbserver71','536871016':'ndbserver72','536871017':'ndbserver73','536871018':'ndbserver74','536871019':'ndbserver75','536871020':'ndbserver76','536871021':'ndbserver77','536871022':'ndbserver78','536871023':'ndbserver79','536871024':'ndbserver80','536871025':'ndbserver81','536871026':'ndbserver82','536871027':'ndbserver83','536871028':'ndbserver84','536871029':'ndbserver85','536871030':'ndbserver86','536871031':'ndbserver87','536871032':'ndbserver88','536871033':'ndbserver89','536871034':'ndbserver90','536871035':'ndbserver91','536871036':'ndbserver92','536871037':'ndbserver93','536871038':'ndbserver94','536871039':'ndbserver95','536871040':'ndbserver96','536871041':'ndbserver97','536871042':'ndbserver98','536871043':'ndbserver99','536871044':'ndbserver100','536871680':'gnbk','537208899':'katie_mount','537208900':'katie_nfs','541414217':'fcagent','545580417':'ugidd','555555554':'inetray.start','555555555':'inetray','555555556':'inetray','555555557':'inetray','555555558':'inetray','555555559':'inetray','555555560':'inetray','591751041':'pnmd','600000001':'collectd','600000002':'xycomd','600000003':'motord','600000004':'fitsd','600100029':'des_crypt','600100069':'fypxfrd','611319808':'rdbx','630474513':'bminrd','788585389':'bwnfsd','805306368':'dmispd','805310465':'sql_disp','805898569':'rdict','806422610':'piktc_svc','822084608':'ilu','822087681':'testpoint','822087682':'awg','822087683':'cgdsrtdd','822087684':'gdsd','822087685':'chnconfd','822087686':'leapconfd','822087687':'rlaunchd','824395111':'cfsd','912680550':'cns','1073741824':'fmproduct','1073741840':'gsql_trn','1092830567':'cfsd','1145324612':'rdb','1289637086':'dtcm','1289637087':'ttsession','1342177279':'ttsession','1431655765':'wdb'}

def assign(service, arg):
	if service == "ip":
		return True, arg
def audit(arg):
	getRpcinfo(arg)

def getRpcinfo(host):
	s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
	payload='\x80\x00\x00\x28\x01\x6a\x31\x2b\x00\x00\x00\x00\x00\x00\x00\x02\x00\x01\x86\xa0\x00\x00\x00\x02\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
	try:
		socket.setdefaulttimeout(20)#超时
		s.connect((host,111))#连接对应主机和端口
		s.send(payload)
		data=s.recv(1024)
		res=[]
		output=[]
		if data[4:8]=='\x01\x6a\x31\x2b':#和之前发送的序号相同,表示是对之前报文的确认ack
			for i in range(28,len(data),20):
				valueFlolows=struct.unpack('i',str(data[i:i+4][::-1]))[0]
				if valueFlolows ==0:
					break
				program= struct.unpack('i',str(data[i+4:i+8][::-1]))[0]
				version= struct.unpack('i',str(data[i+8:i+12][::-1]))[0]
				protocol= struct.unpack('i',str(data[i+12:i+16][::-1]))[0]
				port= struct.unpack('i',str(data[i+16:i+20][::-1]))[0]
				res.append([program,protocol,port,version])
			if len(res)!=0:
				res.sort()
				for i in range(len(res)):
					if len(res)==0:
						break
					a=res.pop(0)
					for j in range(len(res)):
						temp=res[0]
						if a[0]==temp[0] and a[1]==temp[1] and a[2]==temp[2]:
							a[3]="%s,%s"%(a[3],temp[3])
							res.pop(0)
						else:
							break
					output.append(a)
				logs=[]
				resultarg={'host':host,'rpcinfo':[]}
				for i in range(len(output)):
					proto=''
					if output[i][1]==6:
						proto='tcp'
					elif output[i][1]==17:
						proto='udp'
					resultarg['rpcinfo'].append({"programname":getServiceName(output[i][0]),"programnum":output[i][0],"port":output[i][2],"protocol":proto,"versions":output[i][3]})
					#resultarg+=('\t\t|--- %s \t\t %s \t\t\t %s/%s \t\t %s\n'%(output[i][0],output[i][3],output[i][2],proto,getServiceName(output[i][0])))
					#对output里面的内容解释：program:output[i][0],version: output[i][3],port: output[i][2], proto,getServiceName(output[i][0]))
					logs.append('%s/%s => [rpc.%s]%s' % (output[i][2],proto, getServiceName(output[i][0]), '; Ver => %s' % output[i][3]))
				security_note('\n'.join(logs))
				#({'versions': '2,3,4', 'protocol': 'tcp', 'programnum': 100000, 'programname': 'rpcbind', 'port': 111})
				task_push("rpc", resultarg, uuid=None, target=None)
	except Exception :
		pass
	finally:
		s.close()
	#print res
def getServiceName(program):
	global service_dict
	for i in service_dict:
		if str(program)== i:
			return service_dict[i]
	return 'UnknowService'	

if __name__ == '__main__':
	from dummy import *
	audit(assign('ip', '172.18.19.90')[1])